home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4266 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.7 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q:order of evaluation
  5. Date: Mon, 29 Jan 1996 12:56:02 GMT
  6. Organization: Netcom
  7. Message-ID: <310cbc99.219827136@nntp.ix.netcom.com>
  8. References: <4dfhlu$a33$1@mhafn.production.compuserve.com> <hamilton-1801962045570001@dialup-147.austin.io.com> <4dpcfo$293@clarknet.clark.net> <hamilton-2401960104020001@dialup-86.austin.io.com> <3108c867.40236096@nntp.ix.netcom.com> <4eb6kq$ksf@gazette.tandem.com> <31098f8f.11689344@nntp.ix.netcom.com> <4ei45v$mci@axl02it.ntc.nokia.com>
  9. NNTP-Posting-Host: ix-dc7-18.ix.netcom.com
  10. X-NETCOM-Date: Mon Jan 29  4:55:24 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. Risto Lankinen <risto.lankinen@ntc.nokia.com> wrote:
  14.  
  15. > Hi!
  16. > miker3@ix.netcom.com (Mike Rubenstein) wrote:
  17. > >yun_yeogirl <yyg> wrote:
  18. > >
  19. > >> Michael M Rubenstein wrote :
  20. > >> 
  21. > >>         [Example:
  22. > >>           i = v[i++];      // the behavior is undefined
  23. > >> 
  24. > >>           i = ++i + 1;     // the behavior is undefined
  25. > >> 
  26. >    [etc...]
  27. > Isn't the mere existence of this discussion an adequate reason for
  28. > reconsidering the standard when it comes to the evaluation order of
  29. > such expressions?  What I mean is, why does the standard *need* to
  30. > specify that something is 'undefined' when they could be 'defined'
  31. > anyway.  This would have the added bonus that no existing programs
  32. > conforming to the standard won't break simply because they were not
  33. > allowed to make assumptions about undefined behaviour, whereas the
  34. > new programs would have the added power of expression without fear
  35. > of the compilers misinterpreting the intent.
  36. > For example, instead of...
  37. > >>           i = ++i + 1;     // the behavior is undefined
  38. > .. one could define in the standard...
  39. > >>           i = ++i + 1;     // operator+() evaluates and executes
  40. > >>                            // its arguments in the order of their
  41. > >>                            // associativity, ie. '++i' first, the
  42. > >>                            // constant expression '1' next, and
  43. > >>                            // the operator+() last.  Finally, the
  44. > >>                            // result is assigned to 'i'.  Thus the
  45. > >>                            // example equals to 'i = i + 2'.
  46. > .. and within one version cycle all compilers will behave same.
  47. > Or, for curiosity's sake, why not?
  48.  
  49. I don't see the fact that some people just don't bother to learn the
  50. language as a reason, in itself, for changing the standard.  Still,
  51. there would be some advantages to specifying order more closely.
  52.  
  53. But, there would also be disadvantages.  Specification of order cuts
  54. down on optimization possibilities.  On register-poor machines, it is
  55. usually advantageous to evaluate the more complicated subexpression
  56. first, but your rule would prohibit this optimization.  The expression
  57.  
  58.     a + (b + (c + (d * e * f * g)))
  59.  
  60. can be evaluated with only one intermediate if the compiler is allowed
  61. to select the order, but would require 4 under your rule.  Requiring
  62. incrementation to take place immediately places still more burden on
  63. the registers.
  64.  
  65. Is there any evidence that those who do not bother to learn the
  66. present rules will bother to learn the new rules for ordering of
  67. expressions?  I think not.  Look at the problems we have with very
  68. simple things.  The subclause on fflush() (ISO 7.9.5.2) is 12 lines of
  69. text.  The first paragraph of the description is
  70.  
  71.     If stream points to an output stream or an update stream in 
  72.     which the most recent operation was not input, the fflush 
  73.     function causes any unwritten data for that stream to be 
  74.     delivered to the host environment to be written to the file; 
  75.     otherwise the behavior is undefined.
  76.  
  77. Yet we still have people suggesting fflush(stdin).
  78.  
  79.  
  80. Michael M Rubenstein
  81.